package com.xhu.servlet;

import com.xhu.bean.pojo.Emp;
import com.xhu.service.EmpService;
import com.xhu.service.impl.EmpServiceImpl;
import com.xhu.utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/empServlet/*")
public class EmpServlet extends BaseServlet {
    public Map login(HttpServletRequest request){
        //获取前端传入的参数
        String   username=request.getParameter("username");
        String   password=request.getParameter("password");
        //实例对应的业务层实现
        EmpService empService=new EmpServiceImpl();
        Emp  emp=empService.login(username,password);
        // code 状态码  msg 提示信息  data:具体的数据
        Map<String, Object> map = new HashMap<>();
        if(emp!=null) {
            map.put("code", 0);
            map.put("msg", "登录成功");
            map.put("data", emp);
        }else{
            map.put("code", -1);
            map.put("msg", "登录失败,用户名或者密码错误");
            map.put("data", null);
        }
        return map;
    }
    public Map updPassword(HttpServletRequest  request){//ResultData    Rd   R
        System.out.println("===updPassword====");//结果集的封装
        // code 状态码  msg 提示信息  data:具体的数据
        Map<String, Object> map = new HashMap<>();
        if(Math.random()*10>5) {
            map.put("code", 0);
            map.put("msg", "成功");
            map.put("data", "1234");
        }else{
            map.put("code", -1);
            map.put("msg", "修改失败");
            map.put("data", null);
        }
        return   map;
    }
}
